cmake_minimum_required(VERSION 3.10)
project(MQTTProject C CXX)


# 所有可执行文件统一输出到 bin 目录
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin)

# =========================
# 1️⃣ 交叉编译设置
# =========================
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR aarch64)

# 指定交叉编译器
set(CMAKE_C_COMPILER   /usr/bin/aarch64-linux-gnu-gcc)
set(CMAKE_CXX_COMPILER /usr/bin/aarch64-linux-gnu-g++)

# 目标库和头文件路径
set(ARM64_LIB_DIR "${CMAKE_SOURCE_DIR}/arm64-libs")

# 搜索策略
set(CMAKE_FIND_ROOT_PATH ${ARM64_LIB_DIR})
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)

# =========================
# 2️⃣ 编译选项
# =========================
set(CMAKE_BUILD_TYPE Release)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# =========================
# 3️⃣ 头文件
# =========================
include_directories(
    ${CMAKE_SOURCE_DIR}/include
    ${ARM64_LIB_DIR}               # mosquitto 头文件
)

# =========================
# 4️⃣ 库文件
# =========================
link_directories(
    ${ARM64_LIB_DIR}               # mosquitto 动态库
)

# =========================
# 5️⃣ 可执行文件
# =========================
add_executable(mqtt_publisher
    src/BaseMQTTClient.cpp
    src/mqtt_publisher.cpp
    src/MQTTPublisher.cpp
)

add_executable(mqtt_subscriber
    src/BaseMQTTClient.cpp
    src/mqtt_subscriber.cpp
    src/MQTTSubscriber.cpp
)

add_executable(mqtt_client src/main.cpp src/MQTTClient.cpp)
target_link_libraries(mqtt_client mosquitto pthread)


# =========================
# 6️⃣ 链接库
# =========================
target_link_libraries(mqtt_publisher
    mosquitto
    pthread
)

target_link_libraries(mqtt_subscriber
    mosquitto
    pthread
)

# =========================
# 7️⃣ 安装可选（可选）
# =========================
# install(TARGETS mqtt_publisher mqtt_subscriber DESTINATION bin)
